<?php
require_once('inc/sync.php');

class FeedBack {
    
    private static $_instance;

    /**
     * 
     * Create connection database
     * @return Mysql
     * 
     */
    public static function factory() {
        if (!self::$_instance) {
            self::$_instance = new Mysql();
        }
        return self::$_instance;
    }
    
    public static function getId() {
        return self::factory()->getId();
    }
    
    public static function findAll(){
        $query = "SELECT * FROM feedback WHERE status=1";
        return self::factory()->find($query);
    }
    
    public static function findAllLimit($from, $max_result){
        $query = "SELECT * FROM feedback WHERE status=1 LIMIT {$from}, {$max_result}";
        return self::factory()->find($query);
    }


    public static function findLimit(){
        $query = "SELECT * FROM feedback LIMIT 3";
        return self::factory()->find($query);
    }
    
    
    public static function add($param) {
        $arr = array(
            "name" => $param["name"],
            "phone" => $param["phone"],
            "comments" => $param["comment"],
            "time" => time(),
            "status" => 0,
        );
        return self::factory()->insert("feedback", $arr);
    }
    
    public static function addDangky($param) {
        $arr = array(
            "name" => $param["name"],
            "address" => $param["address"],
            "phone" => $param["phone"],
            "email" => $param["email"],
            "time" => time(),
        );
        return self::factory()->insert("dangky", $arr);
    }
    
}

?>
